﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
using System.Data;

namespace Admin.Message.SysMessage
{
    public partial class modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProjectInfo();
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int SysMessageId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(SysMessageId);
                }
            }
        }
        private void BindProjectInfo()
        {
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            DataSet ds = bllBind.GetDataSet("ProjectInfoId,ProjectName", "tb_MidSoft_ProjectInfo", "");
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ChinaSoft.Common.BindControl.BindDropDownList(ddlProjectName, ds, "ProjectName", "ProjectInfoId");
            }
        }
        private void ShowInfo(int sysMessageId)
        {
            ChinaSoft.BLL.BLL_tb_Midsoft_SysMessage bll = new ChinaSoft.BLL.BLL_tb_Midsoft_SysMessage();
            ChinaSoft.Model.Model_tb_Midsoft_SysMessage model = bll.GetModel(sysMessageId);
            if (model != null)
            {
                txtDescript.Text = model.Descript;
                ddlProjectName.SelectedValue = ChinaSoft.Common.Input.SetString(model.ProjectInfoId);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txtDescript.Text.Trim().Length == 0)
            {
                strErr += "描述不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string Descript = this.txtDescript.Text;
            int SysMessageId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
            ChinaSoft.BLL.BLL_tb_Midsoft_SysMessage bll = new ChinaSoft.BLL.BLL_tb_Midsoft_SysMessage();
            ChinaSoft.Model.Model_tb_Midsoft_SysMessage model = bll.GetModel(SysMessageId);
            model.Descript = Descript;

            bll.Update(model);
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}